package com.tuanbiao.utils;

import com.hzjq.data.minbao.entity.AuthEntity;

import java.util.Comparator;

public class AuthLgComparator implements Comparator<AuthEntity.Lgs.Lg> {

    private String diti = "1234567890";
    private StringBuffer buf1 = new StringBuffer();
    private StringBuffer buf2 = new StringBuffer();

    @Override
    public int compare(AuthEntity.Lgs.Lg lg, AuthEntity.Lgs.Lg t1) {
        if (lg == null && t1 == null) return 0;
        if (lg != null && t1 == null) return 1;
        if (lg == null && t1 != null) return -1;
        try {
            buf1.delete(0, buf1.length());
            buf2.delete(0, buf2.length());

            String uid1 = lg.getUid();
            String uid2 = t1.getUid();

            int length = uid1.length();
            for (int i = 0; i < length; i++) {
                String d = uid1.substring(i, i + 1);
                if (diti.contains(d)) {
                    buf1.append(d);
                }
            }


            int length2 = uid2.length();

            for (int i = 0; i < length2; i++) {
                String d = uid2.substring(i, i + 1);
                if (diti.contains(d)) {
                    buf2.append(d);
                }
            }


            long a = Long.parseLong(buf1.toString());
            long b = Long.parseLong(buf2.toString());
            if (a > b) return 1;
            if (a < b) return -1;
        } catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }


}
